<?php

namespace Crm\Controller;

/**
 * LoginController控制器
 *
 * @author SoChishun <14507247@qq.com>
 * @version 1.0
 * @since 1.0.0 <2015-3-23> by SoChishun Added.
 */
class LoginController extends \Think\Controller {

    /**
     * index操作
     * @since 1.0.0 <2015-3-23> by SoChishun Added.
     */
    public function index() {
        layout(false);
        appfn_is_install() || redirect(U('Install/index'));
        $this->display();
    }

    /**
     * 管理员登录操作
     * @param string $userName
     * @param string $password
     * @param string $captcha
     * @since 1.0 <2015-3-23> by SoChishun Added.
     */
    public function login($user_name = '', $password = '', $captcha = '') {
        $admin = D('Admin');
        $data = $admin->admin_login($user_name, $password);
        if (is_array($data)) {
            session(C('USER.SESSION_ID'), $data);
            redirect(U('Index/index'));
        } else {
            $this->error($data);
        }
    }

    /**
     * 登出方法
     * @since 1.0 <2015-3-23> by SoChishun Added.
     */
    public function logout() {
        session(C('USER.SESSION_ID'), null);
        $this->success('登出成功', U('Login/index'));
    }

}
